package com.sdry.web.controller.hpf;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.sdry.model.hpf.FinishProductLibraryIn;
import com.sdry.model.hpf.Page;
import com.sdry.service.hpf.FinishProductLibraryInService;
import com.sdry.utils.ResponseUtil;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;

/**
 * @ClassName: FinishProductLibraryInController 
 * @Description:成品库入库Controller
 * @Author hpf
 * @Date 2019年1月28日 下午4:11:58 
 * @version 1.0
 */
@Controller
@RequestMapping(value="/finishProductLibraryIn")
public class FinishProductLibraryInController {

	@Resource
	private FinishProductLibraryInService finishProductLibraryInService;
	
	/**
	 * 分页查询成品库入库
	 * @param page 分页条件
	 * @param finishProductLibraryIn 查询条件
	 * @param response
	 */
	@RequestMapping(value="/listPageFinishProductLibraryIn")
	public void listPageFinishProductLibraryIn(Page page,FinishProductLibraryIn finishProductLibraryIn,HttpServletResponse response){
		Map<String, Object> map = new HashMap<>();
		map.put("page", page.getPage());
		map.put("limit", page.getLimit());
		if (finishProductLibraryIn.getPname() != null) {
			map.put("pname", finishProductLibraryIn.getPname());
		} else {
			map.put("pname", "");
			finishProductLibraryIn.setPname("");
		}
		List<FinishProductLibraryIn> finishProductLibraryInList = finishProductLibraryInService.listPageFinishProductLibraryIn(map);
		int count = finishProductLibraryInService.countFinishProductLibraryIn(finishProductLibraryIn);
		JSONObject jsonObject = new JSONObject();
		JsonConfig jsonConfig = new JsonConfig();
		JSONArray jsonArray = JSONArray.fromObject(finishProductLibraryInList, jsonConfig);
		jsonObject.put("code", 0);
		jsonObject.put("data", jsonArray);
		jsonObject.put("count", count);
		try {
			ResponseUtil.write(response, jsonObject);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
